import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';

import {
  BaseResponse,
  TimestampsWrapper,
  PageResponse,
} from '@server/basic-dto';
import { DictionaryItem } from '@server/modules/dictionary/dto';

export class CreateOrUpdateBlogDto {
  @ApiProperty({
    description: '语种标题',
    type: String,
  })
  title: string;

  @ApiProperty({
    description: '主图',
    type: String,
  })
  mainPic: string;

  @ApiProperty({
    description: '内容',
    type: String,
  })
  content: string;

  @ApiProperty({
    description: '描述',
    type: String,
  })
  description: string;

  @ApiProperty({
    description: '语言包(字典id)',
    type: String,
  })
  locale: string;

  @ApiProperty({
    description: '是否在首页显示, 0: 不显示, 1: 显示',
    type: Number,
    enum: [0, 1]
  })
  home: number;

  @ApiProperty({
    description: '首页展示时是否显示new, 0: 不显示, 1: 显示',
    type: Number,
    enum: [0, 1]
  })
  newIcon: number;
}

export class BlogDetail extends TimestampsWrapper {
  @ApiProperty({
    description: '语种标题',
    type: String,
  })
  title: string;

  @ApiProperty({
    description: '主图',
    type: String,
  })
  mainPic: string;

  @ApiProperty({
    description: '内容',
    type: String,
  })
  content: string;

  @ApiProperty({
    description: '描述',
    type: String,
  })
  description: string;

  @ApiProperty({
    description: '阅读次数',
    type: Number,
  })
  readCount: number;

  @ApiProperty({
    description: '文章状态, 0: 已发布(未上架), 1: 已上架(官网可以看到), 2: 已隐藏',
    type: Number,
    enum: [0, 1, 2]
  })
  state: number;

  @ApiProperty({
    description: '是否在首页显示, 0: 不显示, 1: 显示',
    type: Number,
    enum: [0, 1]
  })
  home: number;

  @ApiProperty({
    description: '首页展示时是否显示new, 0: 不显示, 1: 显示',
    type: Number,
    enum: [0, 1]
  })
  newIcon: number;

  @ApiProperty({
    description: '语言包(字典id)',
    type: DictionaryItem,
  })
  @Type(() => DictionaryItem)
  locale: DictionaryItem;
}

export class BlogDetailList extends PageResponse {
  @ApiProperty({
    description: '博客列表',
    type: BlogDetail,
    isArray: true,
  })
  @Type(() => BlogDetail)
  list: Array<BlogDetail>;
}

export class BlogDetailResponse extends BaseResponse {
  @ApiProperty({
    description: '博客详情',
    type: BlogDetail,
  })
  @Type(() => BlogDetail)
  data?: BlogDetail
}

export class BlogListResponse extends BaseResponse {
  @ApiProperty({
    description: '列表分页信息',
    type: BlogDetailList,
  })
  @Type(() => BlogDetailList)
  data?: BlogDetailList
}

export class BlogHomeResponse extends BaseResponse {
  @ApiProperty({
    description: '博客列表',
    type: BlogDetail,
    isArray: true,
  })
  @Type(() => BlogDetail)
  data: Array<BlogDetail>;
}